<?php
include_once ("../Login/databaseconnection.php");
$q=$_GET["q"];
$hint="";
$name=explode(",",$q);
$nam=$name[0];
$tn=count($name);
for($i=1;$i<$tn;$i++)
{
if(empty($adr))
{
$adr=$name[$i];
}
else
{
$adr=$adr.",".$name[$i];
}
}
$results= mysql_query("SELECT * FROM school Where Name='$nam' AND Address='$adr'");
if($row = mysql_fetch_array($results))
{
$Sch_Id=$row['School_Id'];
}
$hint=$hint.'<select name="Pro_Name" id="Pro_Name" onChange="getProYear(this.value)">';
   if(isset($_POST['SaveChanges']))
	  {
	  $P_Id=$_SESSION['Pr_Id'];	   
	   unset($_SESSION['Pr_Id']);
	  }
	  if($P_Id!="")
	  {
	  $resultnet=mysql_query("SELECT * FROM programme WHERE Programme_Id='$P_Id'");
  if($rownet=mysql_fetch_array($resultnet))
  {
		$Programme_Name=$rownet['Programme_Name'];
}
	 $hint=$hint.'<option value="'.$Programme_Name.'">'.$Programme_Name.'</option>';
	  }
	    else
	  {
	  $hint=$hint.'<option value="Select One">Select One</option>';
	  }
		if($Sch_Id!="")
		{
			$pro=mysql_query("SELECT DISTINCT(Programme_Id) FROM programmes WHERE School_Id='$Sch_Id'");
		}
		if($Sch_Id=="")
		{
	  $pro=mysql_query("SELECT DISTINCT(Programme_Id) FROM programmes");
		}
  while($row=mysql_fetch_array($pro))
  {
	 $Pro_Id=$row['Programme_Id'];
	 $resultnet=mysql_query("SELECT * FROM programme WHERE Programme_Id='$Pro_Id'");
  if($rownet=mysql_fetch_array($resultnet))
  {
		$Pro_Name=$rownet['Programme_Name'];
}
if($Programme_Name!=$Pro_Name)
{
	  $hint=$hint.'<option value="'.$Pro_Name.'">'.$Pro_Name.'</option>';
	  }
  }
      $hint=$hint.'</select>';
  if($hint=="")
{
$response=$response.'<select name="Pro_Name" id="Pro_Name" onChange="getProYear(this.value)">';
   $response=$response.'<option value="Select One">Select One</option>';
	 $pro=mysql_query("SELECT DISTINCT(Programme_Id) FROM programmes");
	  
  while($row=mysql_fetch_array($pro))
  {
   $Pro_Id=$row['Programme_Id'];
  $resultnet=mysql_query("SELECT * FROM programme WHERE Programme_Id='$Pro_Id'");
  if($rownet=mysql_fetch_array($resultnet))
  {
   $P_Name=$rownet['Programme_Name'];
   }
	 $response=$response.'<option value="'.$P_Name.'">'.$P_Name.'</option>';
  }
$response=$response.'</select>';
}
else
{
$response=$hint;
}
echo $response;
?>